﻿using System.Configuration;
using System.Reflection;
using Newtonsoft.Json.Linq;
using log4net.Util;

namespace Noria.Web.Utility
{
    internal class NConfig
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public static dynamic Root { get; private set; }

        static NConfig()
        {
            Root = LoadNoriaSection().noria;
            log.Info("Noria section loaded.");

            var asm = Assembly.GetCallingAssembly().GetName();
            log.InfoFormat("{0} loaded.", asm.FullName);
        }

        private static dynamic LoadNoriaSection()
        {
            var config = SystemInfo.ConfigurationFileLocation;
            var xml = new ConfigXmlDocument();
            xml.Load(config);

            var node = xml.SelectSingleNode("/configuration/noria");
            return JObject.FromObject(node);
        }
    }
}